package com.zwy.rxjava;

import rx.Observable;
import rx.Subscriber;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class RxJavaDemo1 extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 创建observable
		Observable<String> observable = Observable.create(new Observable.OnSubscribe<String>() {
			@Override
			public void call(Subscriber<? super String> subscriber) {
				subscriber.onNext("Hello RxJava,itchen");
				subscriber.onCompleted();
			}
		});

		// 创建subscriber
		Subscriber<String> subscriber = new Subscriber<String>() {
			@Override
			public void onCompleted() {

			}

			@Override
			public void onError(Throwable e) {

			}

			@Override
			public void onNext(String s) {
				Toast.makeText(RxJavaDemo1.this, s, Toast.LENGTH_SHORT).show();
			}
		};

		// 订阅
		observable.subscribe(subscriber);
	}
}
